package stutterWebApp.server;
 
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.StringReader;

import stutterWebApp.client.StutterService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
 
@SuppressWarnings("serial")
public class StutterWebWrapper extends RemoteServiceServlet implements
StutterService  {

	
	public String callStutter(String stutText) throws IllegalArgumentException {
		PrintStream origOut;
		origOut = System.out;
				try
		{
		ByteArrayOutputStream allOutput = new ByteArrayOutputStream();
			
			allOutput = new ByteArrayOutputStream();
			PrintStream out = new PrintStream(allOutput);

			System.setOut(out);
	 //
			StringReader sReader = new StringReader(stutText);
			
			BufferedReader bReader = new BufferedReader(sReader);

		//Call Stutter pass in the fileName we just created
		Stutter.checkStutter(bReader);
		
		//return output from Stutter
		return allOutput.toString();
		}
		catch (Exception ex)
		{
			System.out.println(ex.getMessage());
			return ex.getMessage();
		}
		finally{
			System.setOut(origOut) ;
		}

	} 

	 
}
